package com.cea.papyrus.multidiagram.extension;

import org.eclipse.gef.ui.actions.DeleteRetargetAction;
import org.eclipse.gef.ui.actions.RedoRetargetAction;
import org.eclipse.gef.ui.actions.UndoRetargetAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.RetargetAction;

import com.cea.papyrus.multidiagram.actions.CreateDiagramRetargetAction;
import com.cea.papyrus.multidiagram.actions.DeleteDiagramAction;
import com.cea.papyrus.multidiagram.actions.DeleteDiagramRetargetAction;
import com.cea.papyrus.multidiagram.gef.GefMultiPagesActionBarContributor;

/**
 * Action bar contributor for multi diagram editor.
 * This action bar contributor takes in charge toolbar buttons declared in extensions 
 * by diagram plugins.
 */
public abstract class MultiDiagramActionBarContributor extends GefMultiPagesActionBarContributor {

	/**
	 * Load actions declared in extensions, and load default actions (undo/redo/delete)
	 * @see org.eclipse.gef.ui.actions.ActionBarContributor#buildActions()
	 */
	protected void buildActions() {
		addRetargetAction(new UndoRetargetAction());
		addRetargetAction(new RedoRetargetAction());
//		addRetargetAction(new DeleteRetargetAction());

		// register create action for each registered editor
		
//		RetargetAction action;
//		for( NestedEditorDescriptor desc : getEditorRegistry().getEditorDescriptors() ){
//			addRetargetAction( new CreateDiagramRetargetAction( desc.getCreateButtonDescriptor()) );
//		}
//		// Delete current diagram
//		addRetargetAction(new DeleteDiagramRetargetAction());
	}

	/**
	 * Return the EditorRegistry for nested editor descriptors.
	 * <p>Subclass should implements this method in order to return the registry associated to the 
	 * extension point namespace.</p>
	 * @return the EditorRegistry for nested editor descriptors.
	 */
	abstract protected EditorFactoryRegistry getEditorRegistry();

	/**
	 * Get the main editor. The main editor should be of appropriate type 
	 * @return the main editor
	 */
	private ExtensionMultiDiagramEditor getMultiDiagramEditor() {
		return (ExtensionMultiDiagramEditor)rootEditor;
	}

	/**
	 * Add retarget actions to the given toolbar.
	 * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(org.eclipse.jface.action.IToolBarManager)
	 */
	public void contributeToToolBar(IToolBarManager toolBarManager) {
		toolBarManager.add(getAction(ActionFactory.UNDO.getId()));
		toolBarManager.add(getAction(ActionFactory.REDO.getId()));
//		toolBarManager.add(getAction(ActionFactory.DELETE.getId()));

//		for( NestedEditorDescriptor desc : getEditorRegistry().getEditorDescriptors() ) {
//			toolBarManager.add( getAction(desc.getCreateButtonDescriptor().getActionID()) );
//		}
//		toolBarManager.add(getAction(DeleteDiagramAction.DELETE_DIAGRAM_ID));
	}

}